 // 云函数入口文件
const cloud = require('wx-server-sdk')
cloud.init({
  env: cloud.DYNMAIC_CURRENT_ENV
})
const db = cloud.database();

// 云函数入口函数
exports.main = async (event, context) => {
  try{
    const { OPENID } = cloud.getWXContext()
    const result = await db.collection('data-message').add({
      data:{
        touser: event.openid, //要推送给那个用户
        page: 'pages/index/index', //要跳转到哪个界面
        name: event.name,
        weather: event.weather,
        date: event.date,
        love: event.love,
        hi: event.hi,
        templateId: event.templateId, //模板id
        issend: false
      }
    })
    console.log(result)
    return result.errCode
  }catch(err){
    console.log(err)
    return err
  }
}